<?php
//http://localhost/1908php3/goodsgocar.php?userid=1&goodsid=1&goodsname=1&goodsprice=1&goodsimg=1&goodsnum=1;
@require_once("toubu.php");
$userid=$_GET["userid"];
$goodsid=$_GET["goodsid"];
$goodsname=$_GET["goodsname"];
$goodsprice=$_GET["goodsprice"];
$goodsimg=$_GET["goodsimg"];
$goodsnum=$_GET["goodsnum"];
$obj=array();
// if($userid,$goodsid,$goodsname,$goodsprice,$goodsimg,$goodsnum){
//     die $obj['msg']='asdasdsad';   
// }
//先判断
$sql ="SELECT COUNT(*) FROM guccicar WHERE  userid =$userid AND goodsid = $goodsid";
$result=mysql_query($sql);
$count=mysql_fetch_array($result);

if($count[0]>0){//大于0商品存在,数量加增加
$sqlo="UPDATE guccicar SET goodsnum=goodsnum+$goodsnum WHERE userid = $userid AND goodsid = $goodsid";

}else{//商品不存在,新增
    $sqlo="INSERT INTO guccicar(userid,goodsid,goodsname,goodsprice,goodsimg,goodsnum)VALUES('$userid','$goodsid','$goodsname','$goodsprice','$goodsimg','$goodsnum')";
}
mysql_query($sqlo);
$item=mysql_affected_rows();

if($item>0){//加购成功
$obj["code"]=1;
$obj["msg"]="加购成功";
}else{
    $obj["code"]=0;
    $obj["msg"]="加购失败"; 
}
echo json_encode($obj);